<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.library.entity.Student" %>
<%
    Student student = (Student)session.getAttribute("student");
    if (student == null) {
%>
    <h3 style="color:red;">请先登录！</h3>
    <a href="${pageContext.request.contextPath}/index.jsp">去登录</a>
<%
        return;
    }
    com.library.entity.Libcard libCard = (com.library.entity.Libcard)request.getAttribute("libCard");
    String sno = student.getSno();
    String sname = student.getUsername();
    String type = student.getType();
    String collage = student.getCollage();
    String major = student.getMajor();
    String birth = student.getBirth() != null ? student.getBirth().toString() : "";
    String originPlace = student.getOriginPlace();
%>
<!DOCTYPE html>
<html>
<head>
    <title>图书管理系统 - 借书证</title>
    <style>
        /* 页面整体样式 */
        body {
            margin: 0;
            padding: 0;
            font-family: Arial, sans-serif;
            background-color: #f5f5f5;
        }

        /* 顶部导航栏样式 */
        .header {
            background-color: #f8f9fa;
            padding: 10px 20px;
            border-bottom: 1px solid #e0e0e0;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .header h1 {
            margin: 0;
            font-size: 20px;
            color: #333;
        }

        .user-info {
            display: flex;
            align-items: center;
        }

        .logout-btn {
            margin-left: 15px;
            padding: 5px 10px;
            background-color: #f8f9fa;
            border: 1px solid #ddd;
            border-radius: 4px;
            cursor: pointer;
            text-decoration: none;
            color: #333;
        }

        /* 左侧导航栏样式 */
        .nav-container {
            width: 200px;
            background-color: #f8f9fa;
            float: left;
            min-height: calc(100vh - 50px);
            border-right: 1px solid #e0e0e0;
        }

        .student-label {
            padding: 15px;
            background-color: #e9ecef;
            font-weight: bold;
            border-bottom: 1px solid #ddd;
        }

        .nav-container ul {
            list-style: none;
            padding: 0;
            margin: 0;
        }

        .nav-container li {
            padding: 15px;
            cursor: pointer;
            border-bottom: 1px solid #e0e0e0;
        }

        .nav-container li:hover {
            background-color: #e9ecef;
        }

        .nav-container li a {
            text-decoration: none;
            color: #333;
            display: block;
        }

        .nav-container li.active {
            background-color: #007bff;
        }

        .nav-container li.active a {
            color: white;
        }

        /* 中间内容区域样式 */
        .content-container {
            margin-left: 200px;
            padding: 20px;
        }

        /* 卡片信息样式 */
        .card-info {
            margin-bottom: 30px;
            background-color: white;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
        }

        /* 表格样式 */
        .libcard-table {
            width: 100%;
            border-collapse: collapse;
            background-color: white;
            margin-bottom: 20px;
        }

        .libcard-table th, .libcard-table td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }

        .libcard-table th {
            background-color: #f8f9fa;
            font-weight: bold;
            width: 150px;
        }

        /* 表单样式 */
        .card-form {
            margin-top: 20px;
        }

        .card-form .form-group {
            margin-bottom: 15px;
        }

        .card-form label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }

        .card-form input[type="text"],
        .card-form input[type="date"] {
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            width: 300px;
        }

        /* 按钮样式 */
        .btn {
            padding: 8px 15px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            margin-right: 10px;
            text-decoration: none;
            display: inline-block;
        }

        .btn:hover {
            background-color: #0069d9;
        }

        .btn-danger {
            background-color: #dc3545;
        }

        .btn-danger:hover {
            background-color: #c82333;
        }

        .btn-warning {
            background-color: #ffc107;
            color: #212529;
        }

        .btn-warning:hover {
            background-color: #e0a800;
        }

        .back-link {
            display: inline-block;
            margin-top: 20px;
            color: #007bff;
            text-decoration: none;
        }

        .back-link:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
<!-- 顶部导航栏 -->
<div class="header">
    <h1>图书管理系统 - 学生端</h1>
    <div class="user-info">
        欢迎您，<%=student.getUsername()%>
        <a href="${pageContext.request.contextPath}/common?method=logout" class="logout-btn">退出登录</a>
    </div>
</div>

<!-- 左侧导航栏 -->
<div class="nav-container">
    <div class="student-label">功能导航</div>
    <ul>
        <li><a href="${pageContext.request.contextPath}/student/book?method=queryBooks">查看书籍</a></li>
        <li><a href="${pageContext.request.contextPath}/student/borrow?method=showUnreturned">还书</a></li>
        <li><a href="${pageContext.request.contextPath}/student/borrowRecord?method=showBorrowRecords">借书记录</a></li>
        <li><a href="${pageContext.request.contextPath}/student/fine?method=showFines">罚款情况</a></li>
        <li class="active"><a href="${pageContext.request.contextPath}/student/libcard?method=showLibCard">借书证</a></li>
        <li><a href="${pageContext.request.contextPath}/student/rank?method=borrowRank">借书排行榜</a></li>
        <li><a href="${pageContext.request.contextPath}/student/rank?method=bookHotRank">热门书籍</a></li>
    </ul>
</div>

<!-- 中间内容区域 -->
<div class="content-container">
    <h2>借书证信息</h2>
    
    <div class="card-info">
        <% if(libCard == null) { %>
            <p>您目前没有借书证，请填写以下信息申请新借书证。</p>
            
            <form class="card-form" action="${pageContext.request.contextPath}/student/libcard" method="post">
                <input type="hidden" name="method" value="applyLibCard"/>
                
                <div class="form-group">
                    <label for="sname">姓名</label>
                    <input type="text" id="sname" name="sname" value="<%=sname%>" required/>
                </div>
                
                <div class="form-group">
                    <label for="type">类型</label>
                    <input type="text" id="type" name="type" value="<%=type%>" required/>
                </div>
                
                <div class="form-group">
                    <label for="collage">学院</label>
                    <input type="text" id="collage" name="collage" value="<%=collage%>" required/>
                </div>
                
                <div class="form-group">
                    <label for="major">专业</label>
                    <input type="text" id="major" name="major" value="<%=major%>" required/>
                </div>
                
                <div class="form-group">
                    <label for="birth">出生日期</label>
                    <input type="date" id="birth" name="birth" value="<%=birth%>" required/>
                </div>
                
                <div class="form-group">
                    <label for="originPlace">籍贯</label>
                    <input type="text" id="originPlace" name="originPlace" value="<%=originPlace%>" required/>
                </div>
                
                <input type="submit" value="新办借书证" class="btn"/>
            </form>
        <% } else { %>
            <table class="libcard-table">
                <tr><th>借书证号</th><td><%=libCard.getCardNo()%></td></tr>
                <tr><th>姓名</th><td><%=libCard.getSname()%></td></tr>
                <tr><th>类型</th><td><%=libCard.getType()%></td></tr>
                <tr><th>学院</th><td><%=libCard.getCollage()%></td></tr>
                <tr><th>专业</th><td><%=libCard.getMajor()%></td></tr>
                <tr><th>出生日期</th><td><%=libCard.getBirth() != null ? libCard.getBirth().toString() : ""%></td></tr>
                <tr><th>籍贯</th><td><%=libCard.getOriginPlace()%></td></tr>
                <tr><th>状态</th><td><%=libCard.getCardType()%></td></tr>
            </table>
            
            <div class="card-actions">
                <% if("正常".equals(libCard.getCardType())) { %>
                    <form action="${pageContext.request.contextPath}/student/libcard" method="post" style="display:inline;">
                        <input type="hidden" name="method" value="reportLossLibCard"/>
                        <input type="submit" value="挂失" class="btn btn-warning"/>
                    </form>
                    <form action="${pageContext.request.contextPath}/student/libcard" method="post" style="display:inline;">
                        <input type="hidden" name="method" value="cancelLibCard"/>
                        <input type="submit" value="注销" class="btn btn-danger"/>
                    </form>
                <% } else if("挂失".equals(libCard.getCardType()) || "注销".equals(libCard.getCardType())) { %>
                    <form action="${pageContext.request.contextPath}/student/libcard" method="post" style="display:inline;">
                        <input type="hidden" name="method" value="reissueLibCard"/>
                        <input type="submit" value="补办借书证" class="btn"/>
                    </form>
                <% } %>
            </div>
        <% } %>
        
        <a href="${pageContext.request.contextPath}/student?method=toHome" class="back-link">返回学生首页</a>
    </div>
</div>
</body>
</html>